//chargelever.txt - Lever which, when pulled, blesses items in a nearby box
//Cell 0,1 - The sdf which must less than num charges to do anything.
// Cell 2 - Num charges of device
// Cell 3 - object of box
// Cell 4,5 - x,y coords of box

beginobjectscript; 

variables;

short range = 0;
short flip_or_not = 0;

body;

beginstate INIT_STATE;

	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
break;

beginstate USE_STATE;

	if (flip_or_not > 0) {
		flip_or_not = 0;
		set_object_icon(ME,10);
		}
		else {
			flip_or_not = 1;
			set_object_icon(ME,11);
			}
	
	if (gf(get_memory_cell(0),get_memory_cell(1) ) < get_memory_cell(2)) {
		play_sound(175);
	
		run_sparkles_on_object(get_memory_cell(3),5,15,2);
		print_str("Pull Lever: Magical sparkles surround a nearby box!");
		if (run_bless_on_space(get_memory_cell(4),get_memory_cell(5)) > 0) {
			inc_flag(get_memory_cell(0),get_memory_cell(1),1);
			print_str("  They pass into the box and disappear from sight.");
			print_str("  (Blessed items have better stats, improve chance to hit, and make user harder to hit.)");
			}
			else {
				print_str("  They float around and fade away without doing anything.");
				
				}
		}
		else {
			print_str("Pull Lever: You pull the lever. You hear a clunk and smell smoke.");
			play_sound(21);
			}
break;
